<?php
namespace app\admin\model;
use think\Model;
use think\Exception;
use think\db;
class Album extends Model
{
    //定义闭包中参数传递作用域问题历来注入对象
    protected $user_id;
    /**
     * 
     * @param string  $user_id 用户id
     * @return array  $result 返回专辑id
     */
    public function getIdByUserId($user_id)
    {
        try {
            $where=array('user_id'=>$user_id);
            $result=Db::table('zx_album')->field('id')->where($where)->select();
            
            if(isset($result))
            {
                return $result;
            }else
            {
               throw new \Exception("fetch failed"); 
            }
        } catch (Exception $e) {
            print ($e->getMessage());
        }
    }
    /**
     * 
     * @param string $user_id 用户id
     * @throws \Exception
     * @return array $result 返回查询的节点id列表
     */
    public function getNodeListsById($user_id)
    {
       try {
           $where=array('user_id'=>$user_id);
           $result=Db::table('zx_album')->field('node_id')->where($where)->select();
           if(isset($result)){
               return $result;
           }else {
               throw  new \Exception("fetc failed");
           }
       } catch (Exception $e) {
           print $e->getMessage();
       } 
    }
    /**
     * @param string $user_id; 用户id
     * @return array  $result 返回根据用户id，查询专辑根据专辑进行查询节
     */
    public function getNodeListsByAlubm($user_id)
    {
        $this->user_id=$user_id;
        try 
        {
            $res= Db::table('zx_album')
            ->field('node_id')
            ->where('id','IN',function ($query){
                $query->table('zx_album')->field('id')->where('user_id',$this->user_id);
            })
            ->select();
            if(isset($res)){
                return $res;
            }else {
                throw  new Exception("fetch failed");
            }
        }catch (Exception $e){
            print $e->getMessage();
        }
      
    }
}